using System;
using System.Collections;
using BitMango;
using BMCommon;
using GTA;
using SevenPieceGame;
using UnityEngine;

public class FreeCoinRewardPopupHandler : MonoBehaviour, IPopupWnd, IHandlerBase
{
	public void DoDataExchange()
	{
	}

	public void OnEnterPopup(object param)
	{
		this.isGetReward = false;
		this.btnRoot.transform.localScale = Vector3.zero;
		this.btnRoot.gameObject.SetActive(true);
		this.shine.transform.localScale = Vector3.zero;
		this.coin.transform.localScale = Vector3.zero;
		this.title.transform.localScale = Vector3.zero;
		this.messageRoot.transform.localScale = Vector3.zero;
		this.btnVideoAdsGetBtn.transform.localScale = Vector3.zero;
		this.coloredPaper.SetActive(false);
		this.SetVideoAds();
		base.StartCoroutine(this.coClearPopupAnimation());
	}

	public void OnLeavePopup()
	{
	}

	private void SetVideoAds()
	{
		/*if (RewardAd.IsAdInterstitialReward("FreeCoinReward"))
		{
			this.btnVideoAds.SetActive(true);
			this.btnVideoAdsDisable.SetActive(false);
		}
		else
		{
			this.btnVideoAds.SetActive(false);
			this.btnVideoAdsDisable.SetActive(true);
		}*/
	}

	private void OnClickVideoAds()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		ADSHelper.ShowRewardedVideoAd((status) =>
		{
			if (status)
			{
				this.isGetReward = true;
				this.btnRoot.gameObject.SetActive(false);
				Wallet.Gain("blockcoin", this.rewardCount * this.videoMul, null);
				Wallet.Save();
				EconomyLog.SendEconomyLog(LOG_FROM.FREE_COIN_GIFT, LOG_TYPE.SUPPLY, "blockcoin", this.rewardCount);
				this.coinInfo.CoinAnimation(this.cam.transform.InverseTransformPoint(this.coinAnimationPosition.transform.position), 5, 0.075f, this.rewardCount * this.videoMul, delegate
				{
					Scene.ClosePopup("FreeCoinRewardPopup", true);
				});
			}
		}, ERVType.SevenPiece.ToString());

	}

	private void OnClickOk()
	{
		BMSoundHelper.Play("se_btnclick", false, 1f);
		UserLayerManager.Instance.CheckInstallToLowUser();
		if (UserLayerManager.Instance.GetCurrentUserLayer() == UserLayerManager.UserLayerType.LowUser
		    || UserLayerManager.Instance.GetCurrentUserLayer() == UserLayerManager.UserLayerType.Organic)
		{
			ADSHelper.ShowInterstitialAd("", AdsDataMgr.EInterstitiaFireScene.Seven);
		}
		
		this.isGetReward = true;
		this.btnRoot.gameObject.SetActive(false);
		Wallet.Gain("blockcoin", this.rewardCount, null);
		Wallet.Save();
		EconomyLog.SendEconomyLog(LOG_FROM.FREE_COIN_GIFT, LOG_TYPE.SUPPLY, "blockcoin", this.rewardCount);
		this.coinInfo.CoinAnimation(this.cam.transform.InverseTransformPoint(this.coinAnimationPosition.transform.position), 5, 0.075f, this.rewardCount, delegate
		{
			Scene.ClosePopup("FreeCoinRewardPopup", true);
		});
	}

	private IEnumerator coClearPopupAnimation()
	{
		BMSoundHelper.Play("se_questreward", false, 1f);
		this.coloredPaper.SetActive(true);
		this.shine.gameObject.Popup(0.5f);
		this.coin.gameObject.Popup(0.5f);
		yield return new WaitForSeconds(0.2f);
		this.title.gameObject.Popup(0.5f);
		yield return new WaitForSeconds(0.2f);
		this.messageRoot.gameObject.Popup(0.5f);
		yield return new WaitForSeconds(0.4f);
		this.btnRoot.gameObject.Popup(0.5f);
		BMSoundHelper.Play("se_gethint", false, 1f);
		yield return new WaitForSeconds(2f);
		this.btnVideoAdsGetBtn.gameObject.Popup(0.5f);
		yield break;
	}

	private void OnEscape()
	{
		if (!this.isGetReward)
		{
			this.OnClickOk();
		}
	}

	[SerializeField]
	private tk2dCamera cam;

	[SerializeField]
	private GameObject curtain;

	public GameObject btnRoot;

	public GameObject coloredPaper;

	public GameObject coin;

	public GameObject coinAnimationPosition;

	public GameObject btnVideoAds;

	public GameObject btnVideoAdsDisable;

	public GameObject btnVideoAdsGetBtn;

	public GameObject shine;

	public GameObject title;

	public GameObject messageRoot;

	public TopOverlayHandler coinInfo;

	private int rewardCount = 10;

	private int videoMul = 4;

	private bool isGetReward;

	[HideInInspector]
	public int num;
}
